import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String s=scanner.nextLine();
            String poker="345678910JQKA2jokerJOKER";
            if(s.contains("joker JOKER")){
                System.out.println("joker JOKER");
            }else{
                String[] str=s.split("-");
                String[] left=str[0].split(" ");
                String[] right=str[1].split(" ");
                if(left.length==4&&right.length!=4){
                    System.out.println(str[0]);
                }else if(right.length==4&&left.length!=4){
                    System.out.println(str[1]);
                }else if(left.length==right.length){
                    System.out.println(poker.indexOf(left[0])>poker.indexOf(right[0])?str[0]:str[1]);
                }else{
                    System.out.println("ERROR");
                }
            }
        }
    }
}












//public class Main {
//    public static void main(String[] args) {
//        Scanner scanner=new Scanner(System.in);
//        while (scanner.hasNext()){
//            int n=scanner.nextInt();
//            if(n<6){
//                System.out.println(0);
//            }else if(n<28){
//                System.out.println(1);
//            }else if(n<496){
//                System.out.println(2);
//            }else if(n<8182){
//                System.out.println(3);
//            }else{
//                System.out.println(4);
//            }
//        }
//    }
//}
